const glob = require('glob')
const DEBUG = process.env.NODE_ENV === "production"

// 服务器多级目录下部署 vuejs 打包文件的目录地址
const ModuleName = process.argv[3] == '--mode' ? process.argv[5] : process.argv[3]
const pages = getEntry()

module.exports = {
    productionSourceMap: false,
	publicPath: DEBUG ? '/' + ModuleName : '/',
	outputDir: 'dist/' + ModuleName,
	pages
};

function getEntry() {
	let entries = {}
	if (!DEBUG) {
		let modules = glob.sync( './src/modules/*/*.js')
		for (let i in modules) {
			let modulePath = modules[i]
			let modulePathArr = modulePath.split('/')
			let module = modulePathArr[modulePathArr.length - 2]
			entries[module] = {
				entry: `src/modules/${module}/main.js`,
				template: `public/index.html`,
				filename: `${module}.html`,
				chunks: ['chunk-vendors', 'chunk-common', module]
			}
		}
	} else {
		entries[ModuleName] = {
			entry: 'src/modules/' + ModuleName + '/main.js',
			template: 'public/index.html',
			filename: 'index.html',
			title: ModuleName,
			chunks: ['chunk-vendors', 'chunk-common', ModuleName]
		}
	}
	return entries
}
